<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='保存商品',active='publish'">
<header th:replace="admin/header::headerFragment(${title},${active})"></header>
<link th:href="@{/admin/plugins/tagsinput/jquery.tagsinput.css}" rel="stylesheet"/>
<link th:href="@{/admin/plugins/select2.dist.css/select2-bootstrap.css}" rel="stylesheet"/>
<link th:href="@{/admin/plugins/toggles/toggles.css}" rel="stylesheet"/>

<link href="//cdn.bootcss.com/multi-select/0.9.12/css/multi-select.css" rel="stylesheet"/>
<link href="//cdn.bootcss.com/select2/3.4.8/select2.min.css" rel="stylesheet"/>
<link th:href="@{/admin/plugins/mditor/css/mditor.min.css}" rel="stylesheet"/>
<link th:href="@{/admin/plugins/dropzone/4.3.0/min/dropzone.min.css}" rel="stylesheet">
<style>
    #tags_tagsinput {
        background-color: #fafafa;
        border: 1px solid #eeeeee;
    }

    #tags_addTag input {
        width: 100%;
    }

    #tags_addTag {
        margin-top: -5px;
    }

    .mditor .editor {
        font-size: 14px;
        font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    }

    .mditor .backdrop, .mditor .textarea, .mditor .viewer {
        font-size: 14px;
    }

    .markdown-body {
        font-size: 14px;
    }

    .note-toolbar {
        text-align: center;
    }

    .note-editor.note-frame {
        border: none;
    }

    .note-editor .note-toolbar {
        background-color: #f5f5f5;
        padding-bottom: 10px;
    }

    .note-toolbar .note-btn-group {
        margin: 0;
    }

    .note-toolbar .note-btn {
        border: none;
    }

    #articleForm #dropzone {
        min-height: 200px;
        background-color: #dbdde0;
        line-height: 200px;
        margin-bottom: 10px;
    }

    #articleForm .dropzone {
        border: 1px dashed #8662c6;
        border-radius: 5px;
        background: white;
    }

    #articleForm .dropzone .dz-message {
        font-weight: 400;
    }

    #articleForm .dropzone .dz-message .note {
        font-size: 0.8em;
        font-weight: 200;
        display: block;
        margin-top: 1.4rem;
    }
</style>
<body class="fixed-left">
<div id="wrapper">
    <div th:replace="admin/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">
                            <th:block th:if="${null != contents}">
                                编辑商品
                            </th:block>
                            <th:block th:unless="${null != contents}">
                                发布商品
                            </th:block>
                        </h4>
                    </div>
                    <div class="col-md-12">

                        <input type="hidden" id="attach_url" th:value="${attach_url}"/>

                        <form id="articleForm">
                            <input type="hidden" name="categories" id="categories"/>
                            <input type="hidden" name="cid"
                                   th:value="${contents!=null and contents.cid!=null}?${contents.cid}: ''" id="cid"/>
                            <input type="hidden" name="status"
                                   th:value="${contents!=null and contents.status !=null}?${contents.status}: 'publish'"
                                   id="status"/>
                            <input type="hidden" name="allowComment"
                                   th:value="${contents!=null and contents.allowComment !=null}?${contents.allowComment}: true"
                                   id="allow_comment"/>
                            <input type="hidden" name="allowPing"
                                   th:value="${contents!=null and contents.allowPing !=null}?${contents.allowPing}: true"
                                   id="allow_ping"/>
                            <input type="hidden" name="allowFeed"
                                   th:value="${contents!=null and contents.allowFeed !=null}?${contents.allowFeed}: true"
                                   id="allow_feed"/>
                            <input type="hidden" name="content" id="content-editor"/>
                            <input type="hidden" name="fmtType" id="fmtType"/>


                            <div class="form-group col-md-6" style="padding: 0 10px 0 0;">
                                <input type="text" class="form-control" placeholder="请输入商品标题（必须）" name="title"
                                       required="required"
                                       aria-required="true"
                                       th:value="${contents!=null and contents.title!=null }?${contents.title}: ''"/>
                            </div>

                            <div class="form-group col-md-6" style="padding: 0 0 0 10px;">
                                <input type="text" class="form-control"
                                       placeholder="自定义访问路径，如：my-first-article  默认为商品id" name="slug"
                                       th:value="${contents!=null and contents.slug !=null}?${contents.slug}: ''"/>
                            </div>

                            <div class="form-group col-md-6" style="padding: 0 10px 0 0;">
                                <input name="tags" id="tags" type="text" class="form-control" placeholder="请填写商品标签"
                                       th:value="${contents!=null and contents.tags !=null}?${contents.tags}: ''"/>
                            </div>

                            <div class="form-group col-md-6">
                                <select id="multiple-sel" class="select2 form-control" multiple="multiple"
                                        data-placeholder="请选择分类...">
                                    <th:block th:if="${null == categories}">
                                        <option value="默认分类" selected="selected">默认分类</option>
                                    </th:block>
                                    <th:block th:unless="${null == categories}">
                                        <th:block th:each="c : ${categories}">
                                            <option th:value="${c.name}" th:text="${c.name}"
                                                    th:selected="${null !=contents and adminCommons.exist_cat(c, contents.categories)}?true:false"></option>
                                        </th:block>
                                    </th:block>
                                </select>
                            </div>

                            <!--<div class="col-md-12">-->
                                <!--<div class="pull-right">-->
                                    <!--<a class="btn" id="dropzone" >添加商品图</a>-->
                                <!--</div>-->
                                <!--<table class="table table-striped table-bordered">-->
                                    <!--<thead>-->
                                    <!--<tr>-->
                                        <!--<th>图片名称</th>-->
                                        <!--<th>图片路径</th>-->
                                        <!--<th>操作</th>-->
                                    <!--</tr>-->
                                    <!--</thead>-->
                                    <!--<tbody>-->
                                    <!--<th:block  th:if="${shopImages}!= null and ${#shopImages.size()}!=0">-->
                                        <!--<th:block th:each="post : ${shopImages.list}">-->
                                            <!--<tr th:cid="${post.cid}">-->
                                                <!--<td th:text="${post.title}"></td>-->
                                                <!--<td th:text="${post.slug}"></td>-->

                                                <!--<td>-->
                                                    <!--<a th:href="@{'/admin/page/'+${post.cid}}"-->
                                                       <!--class="btn btn-primary btn-sm waves-effect waves-light m-b-5"><i-->
                                                            <!--class="fa fa-edit"></i> <span>编辑</span></a>-->
                                                    <!--<a href="javascript:void(0)"-->
                                                       <!--th:onclick="'delPost('+${post.cid}+');'"-->
                                                       <!--class="btn btn-danger btn-sm waves-effect waves-light m-b-5"><i-->
                                                            <!--class="fa fa-trash-o"></i> <span>删除</span></a>-->
                                                    <!--<a class="btn btn-warning btn-sm waves-effect waves-light m-b-5"-->
                                                       <!--th:href="@{'/'+${post.slug}}"-->
                                                       <!--target="_blank"><i-->
                                                            <!--class="fa fa-rocket"></i> <span>预览</span></a>-->
                                                <!--</td>-->
                                            <!--</tr>-->
                                        <!--</th:block>-->
                                    <!--</th:block>-->
                                    <!--</tbody>-->
                                <!--</table>-->
                            <!--</div>-->


                            <div class="clearfix"></div>
                            <div id="md-container" class="form-group">
                                <textarea id="md-editor"
                                          th:utext="${contents!=null and contents.content !=null}?${contents.content}: ''"></textarea>
                            </div>

                            <div class="form-group col-md-3 col-sm-4">
                                <label class="col-sm-4">开启评论</label>
                                <div class="col-sm-8">
                                    <div th:class="${contents!=null and contents.allowComment!=null }?'toggle toggle-success allow-'+${contents.allowComment}:'toggle toggle-success allow-true'"
                                         onclick="allow_comment(this);"></div>
                                </div>
                            </div>

                            <div class="form-group col-md-3 col-sm-4">
                                <label class="col-sm-4">允许Ping</label>
                                <div class="col-sm-8">
                                    <div th:class="${contents!=null and contents.allowPing !=null}?'toggle toggle-success allow-'+${contents.allowPing}:'toggle toggle-success allow-true'"
                                         onclick="allow_ping(this);"></div>
                                </div>
                            </div>

                            <!--<div class="form-group col-md-3 col-sm-4">-->
                                <!--<label class="col-sm-4">允许订阅</label>-->
                                <!--<div class="col-sm-8">-->
                                    <!--<div th:class="${contents!=null and  contents.allowFeed !=null}?'toggle toggle-success allow-'+${contents.allowFeed}: 'toggle toggle-success allow-true'"-->
                                         <!--onclick="allow_feed(this);"></div>-->
                                <!--</div>-->
                            <!--</div>-->

                            <!--<div class="form-group col-md-3">-->
                                <!--<label class="col-sm-5">添加缩略图</label>-->
                                <!--<div class="col-sm-7">-->
                                    <!--<div id="thumb-toggle" class="toggle toggle-success" on="false"-->
                                         <!--thumb_url="${contents.thumbimg}" onclick="add_thumbimg(this);"></div>-->
                                <!--</div>-->
                            <!--</div>-->

                            <!--<div id="dropzone-container" class="form-group col-md-12 hide">-->
                                <!--<div class="dropzone dropzone-previews" id="dropzone">-->
                                    <!--<div class="dz-message">-->
                                        <!--<p>可以为你的商品添加一张缩略图 ;)</p>-->
                                    <!--</div>-->
                                <!--</div>-->
                                <!--<input type="hidden" name="thumbimg" id="thumbimg"/>-->
                            <!--</div>-->

                            <div class="clearfix"></div>

                            <div class="text-right">
                                <a class="btn btn-default waves-effect waves-light" th:href="@{/admin/article}">返回列表</a>
                                <button type="button" class="btn btn-primary waves-effect waves-light"
                                        onclick="subArticle('publish');">
                                    保存商品
                                </button>
                                <button type="button" class="btn btn-warning waves-effect waves-light"
                                        onclick="subArticle('draft');">
                                    存为草稿
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
                <div th:replace="admin/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<div th:replace="admin/footer :: footer"></div>

<script th:src="@{/admin/plugins/tagsinput/jquery.tagsinput.min.js}"></script>
<script th:src="@{/admin/plugins/jquery-multi-select/jquery.quicksearch.js}"></script>

<script th:src="@{/admin/plugins/mditor/js/mditor.min.js}"></script>
<script th:src="@{/admin/plugins/multi-select/0.9.12/js/jquery.multi-select.min.js}"></script>
<script th:src="@{/admin/plugins/select2/3.4.8/select2.min.js}"></script>
<script th:src="@{//cdn.bootcss.com/jquery-toggles/2.0.4/toggles.min.js}"></script>
<script th:src="@{/admin/plugins/dropzone/4.3.0/min/dropzone.min.js}"></script>
<script th:src="@{/admin/plugins/to-markdown/3.1.0/to-markdown.min.js}"></script>
<script th:src="@{/admin/js/article.js}"></script>
<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/
    var tale = new $.tale();

    $("#dropzone").dropzone({
        paramName: "file",
        url: "/admin/attach/upload",
        maxFilesize: 1,
        init: function () {
            this.on("success", function (file, msg) {
                console.log(file);
                if (msg.success !== true) {
                    tale.alertError('上传文件大于1M');
                }
                setTimeout(function () {
                    window.location.reload();
                }, 200);
            });
        }
    });
    var clipboard = new Clipboard('button.copy', {
        text: function (trigger) {
            return $(trigger).attr('url');
        }
    });

    clipboard.on('success', function (e) {
        console.info('Action:', e.action);
        console.info('Text:', e.text);
        console.info('Trigger:', e.trigger);
        e.clearSelection();
    });

    function delAttach(id) {
        tale.alertConfirm({
            title: '确定删除该附件吗?',
            then: function () {
                tale.post({
                    url: '/admin/attach/delete',
                    data: {id: id},
                    success: function (result) {
                        if (result && result.success) {
                            tale.alertOkAndReload('附件删除成功');
                        } else {
                            tale.alertError(result.msg || '附件删除失败');
                        }
                    }
                });
            }
        });
    }
    /*]]>*/
</script>
</body>
</html>